import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

N_values = [1,2]

for N in N_values:
    # Read the data for the current N value
    data = pd.read_csv(f'Spline_C_{N}.csv', header=None)  # Assuming the files are named spline_A_6.csv, spline_A_11.csv, etc.

    # Create a new figure for each plot
    plt.figure(figsize=(10, 8))

    # Plot the spline interpolation data
    plt.plot(data[0], data[1], label=f'N={N}')

    # Plot the exact function f(x) = 1 / (1 + x^2)
    x_exact = np.linspace(-5, 5, 400)
    y_exact = 1 / (1 + x_exact**2)
    plt.plot(x_exact, y_exact, 'k--', label='Exact function')

    # Adding the title, labels, and grid
    plt.title(f'Problem C_{N}')
    plt.xlabel('X')
    plt.ylabel('f(X)')
    plt.grid(True)

    # Add legend to the plot
    plt.legend()

    # Save the plot as a PNG file
    plt.savefig(f'../figure/C_{N}.png')

    # Show the plot
    plt.show()
